//package com.world.rickcloudendpoint.service.net;
//
//import com.world.rickcloudendpoint.common.constant.GlobalConstants;
//import io.netty.channel.ChannelInitializer;
//import io.netty.channel.ChannelPipeline;
//import io.netty.channel.socket.nio.NioSocketChannel;
//import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
//import io.netty.handler.logging.LogLevel;
//import io.netty.handler.timeout.IdleStateHandler;
//
///**
// * @description: 报文处理器初始化
// * @author: jlsong
// * @date: 2021/12/22 23:09:55
// * @version: 1.0
// * *  * LengthFieldBasedFrameDecoder 使用
// * *  head+message length+serial+body
// * <p>
// * 参数maxFrameLength 为数据帧最大长度
// * 参数lengthFieldOffset为version长度表示 从第几个字段开始读取长度，表示同意为head的长度
// * 参数lengthFieldLength表示占用了多少个字节数 具体可查看LengthFieldBasedFrameDecoder的getUnadjustedFrameLength方法
// * 参数lengthAdjustment表示还需要拓展长度，具体表示为serial的长度
// * 参数initialBytesToStrip表示 传递给下个coder的时候跳过多少字节 如果从0开始为 head+messagelength+serial+body全部给下个coder
// */
//public class NetProtoMessageTcpServerChannelInitializer extends ChannelInitializer<NioSocketChannel> {
//
//
//    @Override
//    protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception {
//        ChannelPipeline channelPipLine = nioSocketChannel.pipeline();
//        int maxLength = Integer.MAX_VALUE;
//        channelPipLine.addLast("frame", new LengthFieldBasedFrameDecoder(maxLength, 2, 4, 0, 0));
//        channelPipLine.addLast("encoder", new NetProtoBufMessageTCPEncoder());
//        channelPipLine.addLast("decoder", new NetProtoBufMessageTCPDecoder());
////        int readerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_READ_TIMEOUT;
////        int writerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_WRITE_TIMEOUT;
//        int readerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT;
//        int writerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT;
//        int allIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT;
//
//            channelPipLine.addLast("logger", new GameLoggingHandler(LogLevel.DEBUG));
//        channelPipLine.addLast("idleStateHandler", new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds));
////        channelPipLine.addLast("logger", new LoggingHandler(LogLevel.DEBUG));
//        boolean tcpMessageQueueDirectDispatch = gameServerConfigService.getGameServerConfig().isTcpMessageQueueDirectDispatch();
//        if(tcpMessageQueueDirectDispatch) {
//            channelPipLine.addLast("handler", new GameNetMessageTcpServerHandler());
//        }else{
//            AsyncNettyTcpHandlerService asyncNettyTcpHandlerService = LocalMananger.getInstance().getLocalSpringServiceManager().getAsyncNettyTcpHandlerService();
//            channelPipLine.addLast(asyncNettyTcpHandlerService.getDefaultEventExecutorGroup(), new AsyncNettyGameNetMessageTcpServerHandler());
//        }
//    }
//}
